package net.fltx.icon;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class IconDirEntryEx {
    public byte bWidth;
    public byte bHeight;
    public byte bColorCount;
    public byte bReserved;
    public char wPlanes;
    public char wBitCount;
    public int dwBytesInRes;
    public int dwImageOffset;

    /**
     *
     * @param bWidth
     * @param bHeight
     * @param bColorCount
     * @param bReserved
     * @param wPlanes
     * @param wBitCount
     * @param dwBytesInRes
     */
    public IconDirEntryEx(byte bWidth, byte bHeight, byte bColorCount, byte bReserved, char wPlanes, char wBitCount, int dwBytesInRes) {
        this.bWidth = bWidth;
        this.bHeight = bHeight;
        this.bColorCount = bColorCount;
        this.bReserved = bReserved;
        this.wPlanes = wPlanes;
        this.wBitCount = wBitCount;
        this.dwBytesInRes = dwBytesInRes;
    }

    public int sizeof(){
        return 16;
    }

    public byte[] toByteArray() throws IOException {
        ByteArrayOutputStream  data=new ByteArrayOutputStream(sizeof());
        DataOutputStream buf=new DataOutputStream(data);
        buf.write(new byte[]{bWidth,bHeight,bColorCount,bReserved});
        buf.writeChar(Character.reverseBytes(wPlanes));
        buf.writeChar(Character.reverseBytes(wBitCount));
        buf.writeInt(Integer.reverseBytes(dwBytesInRes));
        buf.writeInt(Integer.reverseBytes(dwImageOffset));
        return data.toByteArray();
    }



}
